<template>

  <div>
    <div id="container" style="width:500px; height:300px"></div>
  </div>
</template>
<script>
  import AMap from 'AMap'
  import axios from 'axios';

  let map, geolocation,mapadd;
  export default {
    data(){
      return {
         addresszb:"33",
        addressname:"66",
        getway:'获取方式'
      }
    },

    mounted: function () {
      this.init()

    },
    watch:{
      addresszb:this.addresszb
    },
    methods: {
      init: function () {
        map = new AMap.Map('container', {

          resizeEnable: true,
          zoom: 10
        })
        AMap.plugin(['AMap.ToolBar', 'AMap.Scale','AMap.Geolocation'], function () {
          map.addControl(new AMap.ToolBar())
          map.addControl(new AMap.Scale())
          map.addControl(new AMap.Geolocation());

          geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            timeout: 10000,          //超过10秒后停止定位，默认：无穷大
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            buttonPosition:'RB'
          });
          geolocation.getCurrentPosition();

          AMap.event.addListener(geolocation, 'complete',  function(data) {
            data.position.getLng() //定位成功返回的经度
            data.position.getLat() //定位成功返回的纬度
            this.addresszb= data.position.getLng()+","+data.position.getLat()
       this.addressname=data.formattedAddress
          this.getway=data.location_type
             console.log( data.position.getLng(),data.position.getLat())

            console.log(data.formattedAddress)
            console.log(this.getway)
            axios.post('http://118.89.115.109:2017',this.addresszb,{'Content-Type' : 'application/x-www-form-urlencoded'})
              .then(function (response) {
                console.log(response);
              })
          }); //返回定位信息

        })
      }
    }
  }
</script>
<style>
</style>
